import { ItemData } from "../../../resource/info/ItemData";
import { ItemsUtil } from "../../shortcuts/item/ItemsUtil";
import { RuneEffectConfig } from "../../../resource/RuneEffectConfig";
import { ColorConfig } from "../../../resource/ColorConfig";
import { SRuneHollyInfo } from "../../../../../Message/Game/SRuneHollyInfo";
import { SecondCareerConfig } from "../../../resource/SecondCareerConfig";
import { ECareerSecondTran } from "../../../../../Message/Public/ECareerSecondTran";
import { SRuneInfo } from "../../../../../Message/Game/SRuneInfo";
import { ItemInfo } from "../../../resource/info/ItemInfo";
import { Language } from "../../../../../extend/language/Language";
import { Cache } from "../../../cache/Cache";
import { ItemConfig } from "../../../resource/ItemConfig";
import { RuneUpgradeConfig } from "../../../resource/RuneUpgradeConfig";
type int = number;
//class RuneUtil
    
    export  class RuneUtil
    {
        

        public static getRuneItemDesc(arg1: ItemData): string
        {
            var loc5=0;
            var loc6=null;
            var loc1="";
            if (ItemsUtil.isHolyRune(arg1)) 
            {
                loc5 = 0;
                while (loc5 < arg1.runeSwallowCodes.length) 
                {
                    loc1 = loc1 + RuneUtil.getRuneItemDesc(new ItemData(arg1.runeSwallowCodes[loc5]));
                    ++loc5;
                }
                return loc1 + "<br>";
            }
            var loc2=arg1.effect;
            var loc3=arg1.itemInfo.item.effectEx;
            var loc4=loc2;
            while (loc4 <= loc3) 
            {
                if (loc6 = RuneEffectConfig.instance.getInfoByTypeAndLevel(loc4, arg1.itemInfo.item.itemLevel)) 
                {
                    loc1 = loc1 + (loc6.describe + "<br>");
                }
                ++loc4;
            }
            return loc1;
        }

        public static getRunesHandbookDesc(arg1: int): string
        {
            var loc1="";
            var loc2=new ItemData(arg1);
            loc1 = loc1 + ("<font size=\'14\' color=\'" + RuneUtil.getColorByLevel(loc2.itemInfo.item.itemLevel) + "\'>" + loc2.name + "</font>   " + RuneUtil.getRuneItemLevelName(loc2));
            loc1 = loc1 + ("<br>" + RuneUtil.getRuneItemDesc(loc2));
            return "<textFormat leading=\'5\'>" + loc1 + "</textFormat>";
        }

        public static getRunesDesc(arg1: Array<any>): string
        {
            var loc3=null;
            var loc4=null;
            var loc1="";
            var loc2=0;
            while (loc2 < arg1.length) 
            {
                if ((loc3 = arg1[loc2]) is ItemData) 
                {
                    loc4 = loc3 as ItemData;
                    loc1 = loc1 + ("<font size=\'14\' color=\'" + ColorConfig.instance.getItemColor(loc4.color).color + "\' >" + loc4.name + "</font>   " + RuneUtil.getRuneItemLevelName(loc4));
                    loc1 = loc1 + ("<br>" + RuneUtil.getRuneItemDesc(loc4));
                    loc1 = loc1 + "<br>";
                }
                else if (typeof loc3 === "int") 
                {
                    loc4 = new ItemData(int(loc3));
                    loc1 = loc1 + ("<font size=\'14\' color=\'" + ColorConfig.instance.getItemColor(loc4.color).color + "\' >" + loc4.name + "</font>   " + RuneUtil.getRuneItemLevelName(loc4));
                    loc1 = loc1 + ("<br>" + RuneUtil.getRuneItemDesc(loc4));
                    loc1 = loc1 + "<br>";
                }
                ++loc2;
            }
            return loc1;
        }

        public static getRuneHollyInfoDesc(arg1: SRuneHollyInfo, arg2: int, arg3: int): string
        {
            var loc1=0;
            var loc2="";
            loc1 = SecondCareerConfig.instance.getSecondCode(ECareerSecondTran._ECareerSecondRune, arg1.hollyCode, arg2, arg3);
            var loc3=new ItemData(loc1);
            loc2 = (loc2 = loc2 + ("<font size=\'14\' color=\'#FF7902\' >" + loc3.name + "</font>   " + RuneUtil.getRuneItemLevelName(loc3))) + "<br>";
            var loc4=0;
            while (loc4 < arg1.seqSwallow.length) 
            {
                loc1 = SecondCareerConfig.instance.getSecondCode(ECareerSecondTran._ECareerSecondRune, arg1.seqSwallow[loc4], arg2, arg3);
                loc3 = new ItemData(loc1);
                loc2 = loc2 + RuneUtil.getRuneItemDesc(loc3);
                ++loc4;
            }
            return loc2;
        }

        public static getRuneInfoDesc(arg1: SRuneInfo, arg2: int, arg3: int): string
        {
            var loc4=0;
            var loc1="";
            var loc2=0;
            while (loc2 < arg1.hollyRunes.length) 
            {
                loc1 = loc1 + (RuneUtil.getRuneHollyInfoDesc(arg1.hollyRunes[loc2], arg2, arg3) + "<br>");
                ++loc2;
            }
            var loc3=[];
            var loc5=0;
            var loc6=arg1.commonRunes;
            for(loc4 of loc6) 
            {
                loc3.push(SecondCareerConfig.instance.getSecondCode(ECareerSecondTran._ECareerSecondRune, loc4, arg2, arg3));
            }
            return loc1 = loc1 + RuneUtil.getRunesDesc(loc3);
        }

        public static getRuneEffectDesc(arg1: ItemInfo): string
        {
            var loc1=arg1.item.descStr;
            if (loc1 == null) 
            {
                return "";
            }
            var loc2=loc1.split(Language.getString(80090));
            if (loc2 == null || loc2.length < 2) 
            {
                return "";
            }
            var loc3;
            if ((loc3 = String(loc2[1]).split(Language.getString(80091))[0]) == null) 
            {
                return "";
            }
            return loc3;
        }

        public static getSameEffectItemCode(arg1: ItemData): int
        {
            var loc4=null;
            var loc5=null;
            var loc6=null;
            var loc8=0;
            var loc9=0;
            var loc11=null;
            var loc12=0;
            var loc13=0;
            var loc1=arg1.effect;
            var loc2=arg1.itemInfo.item.effectEx;
            var loc3=RuneUtil.getRuneEffectBounds(arg1);
            var loc7=Cache.instance.pack.runePackCache.getItemsByJudge();
            var loc10=0;
            while (loc10 < loc7.length) 
            {
                if ((loc11 = loc7[loc10] as ItemData).itemCode == arg1.itemCode) 
                {
                    return loc11.itemCode;
                }
                if (!((loc4 = RuneUtil.getRuneEffectBounds(loc11)) == null || loc4.length == 0)) 
                {
                    loc12 = 0;
                    while (loc12 < loc3.length) 
                    {
                        loc5 = loc3[loc12] as Object /* flash.geom.Point */;
                        loc13 = 0;
                        while (loc13 < loc4.length) 
                        {
                            loc6 = loc4[loc13] as Object /* flash.geom.Point */;
                            if ((loc5.x - loc6.y) * (loc5.y - loc6.x) <= 0) 
                            {
                                return loc11.itemCode;
                            }
                            ++loc13;
                        }
                        ++loc12;
                    }
                }
                ++loc10;
            }
            return 0;
        }

        public static getRuneEffectBounds(arg1: ItemData): Array<any>
        {
            var loc4=0;
            var loc5=null;
            var loc1=[];
            if (!ItemsUtil.isHolyRune(arg1)) 
            {
                loc1.push(new Object /* flash.geom.Point */(arg1.effect, arg1.effectEx));
                return loc1;
            }
            var loc2=arg1.runeSwallowCodes;
            var loc3=0;
            while (!(loc2 == null) && loc3 < loc2.length) 
            {
                loc4 = int(loc2[loc3]);
                if (!((loc5 = ItemConfig.instance.getInfoByCode(loc4)) == null || loc5.item == null)) 
                {
                    loc1.push(new Object /* flash.geom.Point */(loc5.item.effect, loc5.item.effectEx));
                }
                ++loc3;
            }
            return loc1;
        }

        public static getBindInfoByUnBindCode(arg1: int): Array<any>
        {
            var unBindCode: int;
            var isTheSame: Function;

            var loc1;
            isTheSame = null;
            unBindCode = arg1;
            isTheSame = (arg1: ItemInfo): Boolean
            {
                if (arg1.item.codeUnbind == unBindCode) 
                {
                    return true;
                }
                return false;
            }
            return ItemConfig.instance.getItemsByJudge(isTheSame);
        }

        public static getRuneItemLevelName(arg1: ItemData): string
        {
            if (ItemsUtil.isHolyRune(arg1)) 
            {
                return Language.getString(44075);
            }
            var loc1=arg1.itemInfo.item.itemLevel;
            var loc2=Language.getString(44019);
            var loc3=loc1;
            switch (loc3) 
            {
                case 1:
                {
                    loc2 = Language.getString(44019);
                    break;
                }
                case 2:
                {
                    loc2 = Language.getString(44020);
                    break;
                }
                case 3:
                {
                    loc2 = Language.getString(44021);
                    break;
                }
                case 4:
                {
                    loc2 = Language.getString(44022);
                    break;
                }
            }
            return loc2;
        }

        /* internal  */static getColorByLevel(arg1: int): string
        {
            var loc1="#00FF00";
            var loc2=arg1;
            switch (loc2) 
            {
                case 1:
                {
                    loc1 = "#00FF00";
                    break;
                }
                case 2:
                {
                    loc1 = "#00BEFF";
                    break;
                }
                case 3:
                {
                    loc1 = "#FF00FF";
                    break;
                }
                case 4:
                {
                    loc1 = "#FF7902";
                    break;
                }
            }
            return loc1;
        }

        public static getRuneEffectByItemData(arg1: ItemData): Array<any>
        {
            var loc5=null;
            var loc1=arg1.effect;
            var loc2=arg1.itemInfo.item.effectEx;
            var loc3=[];
            var loc4=loc1;
            while (loc4 <= loc2) 
            {
                loc5 = RuneEffectConfig.instance.getInfoByTypeAndLevel(loc4, arg1.itemInfo.item.itemLevel);
                loc3.push(loc5);
                ++loc4;
            }
            return loc3;
        }

        public static getRuneUpdateNeedGrow(arg1: int): int
        {
            var loc1=RuneUpgradeConfig.instance.getInfoByCode(arg1);
            if (loc1) 
            {
                return loc1.needGrowth;
            }
            return 0;
        }

        public static getRuneItemNowGrow(arg1: ItemData): int
        {
            if (!arg1.itemExInfo) 
            {
                return 0;
            }
            return arg1.itemExInfo.rune_grow;
        }

        public static getRuneEffectPreNum(arg1: int, arg2: int=0): number
        {
            arg2 = arg2 != 0 ? -1 : 1;
            return arg2 * arg1 % 1000;
        }

        public static getRuneEffectBaseNum(arg1: int, arg2: int=0): int
        {
            arg2 = arg2 != 0 ? -1 : 1;
            return arg2 * Math.floor(arg1 / 1000);
        }

        public static getRuneEffectResult(arg1: int, arg2: int, arg3: int=0, arg4: Boolean=true, arg5: Boolean=true): number
        {
            arg3 = arg3 != 0 ? -1 : 1;
            if (arg4) 
            {
                if (arg5) 
                {
                    return Math.floor(arg1 * (1 + arg3 * RuneUtil.getRuneEffectPreNum(arg2) / 100) + arg3 * RuneUtil.getRuneEffectBaseNum(arg2));
                }
                return Math.floor(arg1 * arg3 * RuneUtil.getRuneEffectPreNum(arg2) / 100 + arg3 * RuneUtil.getRuneEffectBaseNum(arg2));
            }
            if (arg5) 
            {
                return arg1 + arg3 * arg2;
            }
            return arg3 * arg2;
        }
    }
